package com.fr.report.semantic;

import com.fr.base.Style;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.data.condition.Condition;
import com.fr.data.core.DataXMLUtils;
import com.fr.data.util.function.AbstractDataFunction;
import com.fr.report.CellElement;
import com.fr.report.DefaultCellElement;
import com.fr.report.cellElement.CellExpandAttr;
import com.fr.report.cellElement.TableDataColumn;
import com.fr.report.cellElement.core.DSColumn;
import com.fr.report.cellElement.core.RecordGrouper;
import com.fr.report.cellElement.core.SummaryGrouper;
import com.fr.report.io.xml.ReportXMLUtils;
import java.io.Serializable;

public class WizardCellElement
  implements XMLReadable, Serializable, Cloneable
{
  private String tableDataName;
  private String columnName;
  private Style style = Style.DEFAULT_STYLE;
  private Condition condition;
  private int summary = 0;
  private int order = 1;
  private int rowHeight = 19;
  private int columnWidth = 72;

  public String getTableDataName()
  {
    return this.tableDataName;
  }

  public void setTableDataName(String paramString)
  {
    this.tableDataName = paramString;
  }

  public String getColumnName()
  {
    return this.columnName;
  }

  public void setColumnName(String paramString)
  {
    this.columnName = paramString;
  }

  public Condition getCondition()
  {
    return this.condition;
  }

  public void setCondition(Condition paramCondition)
  {
    this.condition = paramCondition;
  }

  public Style getStyle()
  {
    return this.style;
  }

  public void setStyle(Style paramStyle)
  {
    this.style = paramStyle;
  }

  public int getSummary()
  {
    return this.summary;
  }

  public void setSummary(int paramInt)
  {
    this.summary = paramInt;
  }

  public int getOrder()
  {
    return this.order;
  }

  public void setOrder(int paramInt)
  {
    this.order = paramInt;
  }

  public void setRowHeight(int paramInt)
  {
    this.rowHeight = paramInt;
  }

  public void setColumnWidth(int paramInt)
  {
    this.columnWidth = paramInt;
  }

  public int getRowHeight()
  {
    return this.rowHeight;
  }

  public int getColumnWidth()
  {
    return this.columnWidth;
  }

  public CellElement toCellElement()
  {
    return toCellElement(0, 0);
  }

  public CellElement toCellElement(int paramInt1, int paramInt2)
  {
    return toCellElement(paramInt1, paramInt2, 0);
  }

  public CellElement toCellElement(int paramInt1, int paramInt2, byte paramByte)
  {
    return toCellElement(paramInt1, paramInt2, 1, 1, paramByte);
  }

  public CellElement toCellElement(int paramInt1, int paramInt2, int paramInt3, int paramInt4, byte paramByte)
  {
    TableDataColumn localTableDataColumn;
    DefaultCellElement localDefaultCellElement = new DefaultCellElement(paramInt1, paramInt2, paramInt3, paramInt4, null);
    CellExpandAttr localCellExpandAttr = localDefaultCellElement.getCellExpandAttr();
    if (localCellExpandAttr == null)
    {
      localCellExpandAttr = new CellExpandAttr();
      localDefaultCellElement.setCellExpandAttr(localCellExpandAttr);
    }
    localCellExpandAttr.setDirection(paramByte);
    localCellExpandAttr.setExtendable(0);
    Object localObject1 = localDefaultCellElement.getValue();
    DSColumn localDSColumn = null;
    if ((localObject1 == null) || (!(localObject1 instanceof DSColumn)))
    {
      localDSColumn = new DSColumn();
      localDefaultCellElement.setValue(localDSColumn);
    }
    localDSColumn = (DSColumn)localDefaultCellElement.getValue();
    localDSColumn.setDSName(this.tableDataName);
    String str = this.columnName;
    if (str.startsWith("#"))
    {
      int i = Integer.parseInt(str.substring(1));
      localTableDataColumn = TableDataColumn.createColumn(i);
    }
    else
    {
      localTableDataColumn = TableDataColumn.createColumn(str);
    }
    localDSColumn.setColumn(localTableDataColumn);
    localDSColumn.setOrder(this.order);
    if (this.condition != null)
      localDSColumn.setCondition(this.condition);
    if (this.summary != 0)
    {
      localObject2 = new SummaryGrouper();
      ((SummaryGrouper)localObject2).setFunction(AbstractDataFunction.createDataFunction(this.summary));
      localDSColumn.setGrouper((RecordGrouper)localObject2);
    }
    Object localObject2 = getStyle();
    localObject2 = ((Style)localObject2).deriveTextStyle(0);
    localDefaultCellElement.setStyle((Style)localObject2);
    return ((CellElement)localDefaultCellElement);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str2 = paramXMLableReader.getTagName();
      if ("WCellAttr".equals(str2))
      {
        String str1;
        if ((str1 = paramXMLableReader.getAttr("tableDataName")) != null)
          setTableDataName(str1);
        if ((str1 = paramXMLableReader.getAttr("columnName")) != null)
          setColumnName(str1);
        if ((str1 = paramXMLableReader.getAttr("order")) != null)
          setOrder(Integer.parseInt(str1));
        if ((str1 = paramXMLableReader.getAttr("summary")) != null)
          this.summary = Integer.parseInt(str1);
        if ((str1 = paramXMLableReader.getAttr("columnWidth")) != null)
          this.columnWidth = Integer.parseInt(str1);
        if ((str1 = paramXMLableReader.getAttr("rowHeight")) != null)
          this.rowHeight = Integer.parseInt(str1);
      }
      else if ("Style".equals(str2))
      {
        setStyle(ReportXMLUtils.readFullStyle(paramXMLableReader));
      }
      else if ("Condition".equals(str2))
      {
        this.condition = DataXMLUtils.readXMLCondition(paramXMLableReader);
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("WCellAttr").attr("tableDataName", getTableDataName()).attr("columnName", getColumnName()).attr("order", getOrder()).attr("summary", getSummary()).attr("columnWidth", getColumnWidth()).attr("rowHeight", getRowHeight()).end();
    if (getStyle() != null)
      ReportXMLUtils.writeStyle(paramXMLPrintWriter, this.style);
    if (this.condition != null)
      DataXMLUtils.writeXMLCondition(paramXMLPrintWriter, this.condition);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    WizardCellElement localWizardCellElement = (WizardCellElement)super.clone();
    if (this.condition != null)
      localWizardCellElement.setCondition((Condition)this.condition.clone());
    return localWizardCellElement;
  }
}